class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def deleteNode(self, head: ListNode, val: int) -> ListNode:
 
        dummy = ListNode(-1)
        dummy.next = head
        pre = dummy
        next_head = pre.next
        while next_head:
            if next_head.val==val:
                pre.next = next_head.next
                break
            pre = next_head
            next_head = next_head.next
        return dummy.next
